package com.skit.ecm.doraemonkit

import android.content.Context
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatEditText
import androidx.core.content.ContentProviderCompat.requireContext
import com.didichuxing.doraemonkit.kit.AbstractKit
import com.skit.ecm.R

class DebugUrlDialogKit : AbstractKit() {
    override val icon: Int
        get() = R.mipmap.dk_sys_info
    override val name: Int
        get() = R.string.debug_url

    override fun onAppInit(context: Context?) {

    }

    override fun onClick(context: Context?) {
        if (context == null) return
        val sharedPreferences =
            context.getSharedPreferences("debug", Context.MODE_PRIVATE)

        val editText = AppCompatEditText(context).apply {
            hint = "请输入URL，带http://或https://"
            setPadding(50, 20, 50, 20)
            background = null
        }

        editText.setText(sharedPreferences.getString("url", null))
        AlertDialog.Builder(context)
            .setTitle("Debug URL设置")
            .setView(editText)
            .setPositiveButton("确认") { dialog, which ->
                sharedPreferences.apply {
                    edit().putString("url", editText.text.toString()).apply()
                }
            }
            .setNegativeButton("取消", null)
            .create()
            .show()
    }
}